<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>简易轮播图</title>
    <style>
        .slider {
            width: 600px;
            height: 300px;
            margin: 50px auto;
            overflow: hidden;
            position: relative;
        }

        .slide-container {
            width: 3600px;
            /* 假设有6张图片，每张宽度600px */
            position: absolute;
            left: 0;
        }

        .slide {
            float: left;
            width: 600px;
            height: 300px;
        }

        .slide img {
            width: 100%;
            height: 100%;
        }

        .prev,
        .next {
            cursor: pointer;
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            font-size: 30px;
            color: white;
            background-color: rgba(0, 0, 0, 0.5);
            padding: 10px;
        }

        .prev {
            left: 10px;
        }

        .next {
            right: 10px;
        }
    </style>
</head>

<body>

    <div class="slider">
        <div class="slide-container">
            <div class="slide"><img src="./img/1.jpg" alt="Image 1"></div>
            <div class="slide"><img src="./img/2.jpg" alt="Image 2"></div>
            <div class="slide"><img src="./img/3.jpg" alt="Image 3"></div>
            <div class="slide"><img src="./img/4.jpg" alt="Image 4"></div>
            <div class="slide"><img src="./img/5.jpg" alt="Image 5"></div>
            <div class="slide"><img src="./img/6.jpg" alt="Image 6"></div>
        </div>
        <div class="prev">&#10094;</div>
        <div class="next">&#10095;</div>
    </div>

    <script src="./jqurey/jquery-3.7.0.min.js" type="text/javascript">
    </script>
    <script>
        $(document).ready(function () {
            var autoSlider;
            var slideWidth = $('.slide').width();
            var currentSlide = 1;
            var totalSlides = $('.slide').length;

            function moveSlide() {
                if (currentSlide < totalSlides) {
                    $(".slide-container").animate({
                        
                        left: '-=' + slideWidth 
                    });
                    currentSlide++;
                } else {
                    $(".slide-container").animate({
                        left: 0+'px'
                    });
                    currentSlide = 1;
                }
            }

            function startSlider() {
                autoSlider = setInterval(moveSlide, 3000);
            }

            startSlider();

            $('.slider').hover(function () {
                clearInterval(autoSlider);
            }, function () {
                startSlider();
            });

            $('.prev').click(function () {
                if (currentSlide > 1) {
                    $('.slide-container').animate({
                        left: '+=' + slideWidth
                    });
                    currentSlide--;
                } else {
                    $('.slide-container').animate({
                        left: -(slideWidth * (totalSlides - 1))
                    });
                    currentSlide = totalSlides;
                }
            });

            $('.next').click(function () {
                moveSlide();
            });
        });
    </script>

</body>

</html>